<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<?php
    if(isset($_REQUEST['btnSearchBooks']))
    {
        $searchText = $_REQUEST['txtSearchText'];
        $searchBy = $_REQUEST['cmbSearchBy'];
        
        require 'lib/util.php';
        
        if ($searchBy == 1)
        {
            $sql = "SELECT * FROM LIBRARY_BOOKS_FOR_LEND WHERE Title_en LIKE '%" . $searchText . "%'";
        }
        elseif ($searchBy == 2)
        {
            $sql = "SELECT * FROM LIBRARY_BOOKS_FOR_LEND WHERE Title_en LIKE '%" . $searchText . "%'";
        }
        $rs = executeSqlQuery($sql);
        $rowCount = mysql_num_rows($rs);
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <title></title>
    </head>
    <body>
        <?php
            session_start();
            include("/common/headerPage.php")
        ?>
        <div>
            <div id="menu_wrapper"></div>
        <?php
            if (isset($_SESSION['UserID'])&& isset($_SESSION['UserFirstName']) && isset($_SESSION['UserLastName']) && isset($_SESSION['UserRole']))
            {
                echo "<br><br><br><br><br>";
                
                echo "<a href=\"func/logoutHandler.php\">Library</a><br>";
                echo "<a href=\"invHome.php\">Inventory</a><br>";
                echo "<a href=\"func/logoutHandler.php\">Finance</a><br>";
                echo "<a href=\"memHome.php\">Members</a><br>";
            }
            else
            {
                
                if (isset($_SESSION['ErrorMsg']))
                {
                    echo $_SESSION['ErrorMsg'];
                }
            }
        ?>
            <div id="content_wrapper">
                <div id="fh_regular">You Can Search</div>
                <form action="index.php" method="post">
            <table>
                <tr>
                    <td><input class="text_reg" type="text" name="txtSearchText" id="txtSearchText" /></td>
                    <td>
                        <select class="text_reg" id="cmbSearchBy" name="cmbSearchBy">
                            <option value="1" selected="selected">By Title</option>
                            <option value="2">By Author</option>
                        </select>
                    </td>
                    <td><input class="text_reg" type="submit"  value="Search" name="btnSearchBooks" id="btnSearchBooks" /></td>
                </tr>
            </table>
        </form>
                <?php
                    if((isset($_REQUEST['btnSearchBooks']) && $rowCount > 0))
                    {
                        $printRowNumber = 1;
                ?>
                
                <table>
                    <tr>
                        <td>#</td>
                        <td>Book Title</td>
                        <td>Book Category</td>
                        <td>Author</td>
                        <td>Availability</td>
                    </tr>
                    <?php
                                    while ($row = mysql_fetch_array($rs))
                                    {
                    ?>
                    <tr>
                        <td><?php echo $printRowNumber ?></td>
                        <td><?php echo $row['Title_en'] . " | " . $row['Title_si'] ?></td>
                        <td><?php echo $row['CategoryID'] ?></td>
                        <td><?php echo $row['FirstName'] . " " . $row['MiddleName']. " " . $row['LastName'] ?></td>
                        <td>Availability</td>
                    </tr>
                    <?php
                                        $printRowNumber++;
                                    }
                                    ?>
                </table>
                
                <?php
                    }
                ?>
            </div>
            
        </div>
        <?php
            include ("/common/footerPage.php");
        ?>
        

        
    </body>
</html>
